package main

import (
	"fmt"
	"log"
	"net"
	"os"
)

func serverEcho(port string) {
	hostPort := "0.0.0.0:" + port
	l, e := net.Listen("tcp4", hostPort)
	if e != nil {
		log.Println(e.Error())
		os.Exit(0)
	}
	for {
		conn, err := l.Accept()
		if err != nil {
			log.Println(err.Error())
			os.Exit(0)
		}
		go handleEcho(conn)
	}
}

func handleEcho(conn net.Conn) {
	defer conn.Close()
	// rootName := viper.GetString("root.name")
	// rootDes := viper.GetString("root.description")
	b := make([]byte, 1000, 1000)

	fmt.Println("++++++++++")

	conn.Read(b)
	fmt.Println("Recv: ", string(b))
	conn.Write(b)
	fmt.Println("Send: ", string(b))

	fmt.Println("----------")
	fmt.Println("")
}
